//定义ng-app，controller，service
angular.module("myApp",[])
.controller("communityRrecommendMate",["$scope","communityRrecommendMateSeiver","communityRrecommendMateSver",function($scope,communityRrecommendMateSeiver,communityRrecommendMateSver){
	//点击回到上个页面
	$scope.gol = function(){
	 	window.history.go(-1);
	}
	// ==============推荐板块2===============
	communityRrecommendMateSeiver.getData().success(function(res){
		$scope.items = res.data;
	})
	//======================推荐板块1===============================
	communityRrecommendMateSver.getData().success(function(res2){
		$scope.items2 = res2.data;
	})
	//========================================================
	//点击目的地的左边栏右边出现，用下标对应相应的数据
	//定义变量
	$scope.des=0;//接受下标
	$scope.states = "";//接受点击后的对象，改变样式
	$scope.fg = function(a,e){
		$scope.des = a;
		//如果不为空  上一次点击的对象恢复原样式
		if($scope.states!=null){
			$scope.states.className="community_recommend_mateList1_b2Left1"
		};
		//得到对应的点击对象，设置点击后的样式
		e.target.setAttribute("class","community_recommend_mateList1_b2Left1_click");
		//保留上一次点击的对象
		$scope.states = e.target;
	}
	//================================================

	$scope.data1 = "";
	$scope.times = function(e){
		if($scope.data1 !=null){
			$scope.data1 = "";
		}
		$scope.data1 = e.target.innerHTML.slice(7,9);
		console.log(e.target.innerHTML.slice(7,9)+"-")
		document.getElementsByClassName('community_recommend_mateList1_a1_cont')[0].innerHTML = e.target.innerHTML;
	}

	// ====================筛选关键字=============================
	//定义一个变量
	$scope.searchKey = "";
	$scope.fh=function(e){
		if($scope.searchKey !=null){
			$scope.searchKey ="";
		}
		//点击时对应的字获取到
		$scope.searchKey =e.target.innerHTML;
		//字写入框内
		document.getElementsByClassName('community_recommend_mateList1_a2_cont')[0].innerHTML = e.target.innerHTML;
	}
	//====================点击切换隐藏和显示===================
	//用ng-if ,定义变量$scope.contents接受对应的id值，
	//$scope.open定义true/false让主页面内容显示或隐藏
	$scope.contents=0;
	$scope.open=true;//首先主页面显示
	//点击函数，给时间和目的地绑定函数Dun,
	$scope.Dun=function(e){
		//点击时，获取点击时对象的id
		$scope.contents=e.target.id;
		//如果当主页面是打开 然后点击时上边兰那么，主页会关闭，点击对应的id打开
		if ($scope.open&&(e.target.id==1) || ($scope.open&&(e.target.id==2))) {
			$scope.open=false;
		//点击第二次的时候，页面打开，id赋值为0，
		}else if(!$scope.open&&e.target.id==1 || (!$scope.open&&(e.target.id==2))){
			$scope.open=true;
			$scope.contents=0;
		}	
	}
}])
//======================获取2组json数据= 主页面数据=======================
.service("communityRrecommendMateSeiver",function($http){
	this.getData = function(){
		return $http.get("../../../../data/shequjiebanyou.json")
	}
})
//=========================时间目的地数据=====================
.service("communityRrecommendMateSver",function($http){
	this.getData = function(){
		return $http.get("../../../../data/shequtime.json")
	}
})
